Skip to content

Share SQL stages and dispatch validated numerical kernels - #302

Draft
cromwellian wants to merge 3 commits into
xqlsystems:mainfrom
cromwellian:codex/shared-kernel-execution
Draft

cromwellian wants to merge 3 commits into
xqlsystems:mainfrom
cromwellian:codex/shared-kernel-execution

Conversation

@cromwellian

@cromwellian cromwellian commented Nov 2, 2026 •

Copy link
Copy Markdown

🛠️ Codex

Evaluate reachable shared CTEs once per invocation and reuse their stage programs while keeping ddx differentiation of the original SQL/views. Add session-local EinFold numerical dispatch for explicit float64 CPU or float32 MLX GPU execution, deterministic function eligibility, fresh physical state, ordered Arrow providers and bounded coordinate reuse. Ordinary SQL remains the fallback for unsupported semantics.

Depends on CPU setup/preparation #301 and EinFold’s kernel-backend PR. Incremental review: cromwellian/xarray-sql@codex/training-plan-reuse...codex/shared-kernel-execution . GitHub requires fork PRs to target upstream main, so the default diff includes the predecessor until it merges.

Measured tiny-model shared CPU/GPU warm steps improved 314→206 ms (1.53×) and 371→224 ms (1.66×), with fewer repeated kernel dispatches. GPU alone did not solve large-model backward/Arrow overhead. The separate compact-array and resident-training PRs address those remaining costs. The performance/evidence PR retains the detailed workloads and raw results.

The optional installer builds a pinned commit from the separate EinFold fork; native sources and patches are not duplicated here. Validation of the full contribution stack: 714 non-integration tests passed against rebuilt dependency wheels, including SQL masks/NULLs, custom-function overrides, changing inputs, coordinates and snapshots. Rust formatting and changed-file Ruff checks passed. GPU arithmetic remains explicit float32.

Ray and others added 3 commits November 1, 2026 23:24
Support prepared SQL gradients, arithmetic chunk-grid counts and direct Arrow registration. Preserve Context metadata through extension installation, expose target partitions and guard physical reuse against value-dependent filters.

Co-Authored-By: GPT-6 <noreply@openai.com>
Materialize shared reachable CTEs once, reuse stage programs with fresh physical state, and retain ddx differentiation of original views. Add optional session-local float64 CPU and float32 MLX kernel execution with SQL validation and fallback, using the separately maintained EinFold feature build.

Co-Authored-By: GPT-6 <noreply@openai.com>
Build the upstream-compatible feature commit from the contribution fork.

Co-Authored-By: GPT-6 <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@alxmrs

alxmrs commented Nov 4, 2026

Copy link
Copy Markdown
Member

🌀 Claude: Thank you. The measurements here are excellent: 1.53× on the tiny model from computing each CTE once, with every result checked. They show clearly what recomputing CTEs costs us. This PR's concerns are about where the code lives rather than whether it works. I've opened #307 to decide where each piece should go.

Strengths

  • Ordinary SQL stays the fallback, and ddx still differentiates the original views, so gradients don't depend on how the forward pass is staged.
  • GPU float32 is an explicit opt-in, and the tolerances per host (host.rtol, host.atol) say so honestly.
  • The tests cover NULLs, function overrides, changing inputs and snapshots.

Concerns

  1. SharedExecutor is CTE materialization inside xarray-sql. That includes a SQL parser (sqlparser) in our Rust crate, a whitelist of functions, and stage caching. We decided to leave computing each CTE once to DataFusion (DataFusion plans a CTE once per reference, so ML queries grow exponentially with depth #267, on its roadmap) and to work with its developers on it, rather than carry our own.

  2. xarray_sql/mlx.py is an einfold backend. It's built on einfold#156's interface and belongs with einfold, or in a small package of its own. xarray-sql would pass it through.

  3. Private imports across repositories: einfold._native and ddxdb._ddxdb.to_sql, plus a subclass of ddx's DataFusionBackend. A refactor in either project would break xarray-sql.

  4. The build script installs a fork. accelerators/einfold_mlx/build.py clones a personal fork at a pinned commit into the user's environment. That should become a released einfold once einfold#156 lands.

  5. Demo 2's SQL. The demos are meant to be plain, legible SQL, with slowness fixed in the engine:

    • The exact_gelu, dropout and grouped_softmax flags branch the model's SQL.
    • grouped_softmax rewrites the softmax for the engine's sake.
    • The comment explaining why the max is subtracted is deleted.

    Exact GELU and dropout are fair parts of the nanoGPT recipe. They could be the demo's only spelling rather than flags.

I'd hold this PR until #307 settles. The pieces that stay in xarray-sql (the host tolerances, and the demos on public APIs) could then land on their own.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants